package com.itqf;

import com.itqf.dao.UserDao;
import com.itqf.service.impl.UserServiceImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/11/9
 * @Time: 上午10:55
 */
public class TestSpring {
    public  static  void  main(String[]args){

        //1.解析spring的配置文件 xml解析
        //2.构建对象   spring的底层都实现类

        ApplicationContext ac = new
                ClassPathXmlApplicationContext("applicationContext.xml");

        //获取对象      <bean id="userDao" name="myUserDao" class="com.itqf.dao.impl.UserDaoImpl" ></bean>
        //1.根据id获取对象
        UserDao userDao =(UserDao) ac.getBean("userDao");

        //2.第二种获取对象的方式  根据name获取
        UserDao userDao1 = (UserDao) ac.getBean("myUserDao");

        //3.根据字节码得到对象
       // UserDao userDao2 = ac.getBean(UserDaoImpl.class);

        System.out.println(userDao);

        userDao.insert();

        //练习：如何通过Spring构建并获取Service层的对象？？

        System.out.println("------=------service---------");
        UserServiceImpl userService = (UserServiceImpl) ac.getBean("userService");
//        //调用set方法给UserDao属性赋值
//        userService.setUserDao(userDao);

        userService.insert();


    }
}
